/**
 * @author gao
 * @date 2025/6/21 19:05
 */

public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        // 创建一个实现了Runnable接口的实例
        Runnable myRunnable = new MyRunnable();
        // Runnable本身没有start方法，需要配合Thread类来使用
        // 创建一个Thread对象，并将myRunnable作为参数传入
        Thread thread = new Thread(myRunnable);
        // 启动线程
        thread.start();
        while (true) {
            System.out.println("Hello Main!");
            Thread.sleep(1000);
        }
    }
}

class MyRunnable implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.out.println("Hello Tread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}